package pe.com.mowa.siscobsms.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import pe.com.mowa.siscobsms.datos.conTarifa;
import pe.com.mowa.siscobsms.bean.tarifa;
import pe.com.mowa.siscobsms.bean.proyecto;

/**
 * Servlet implementation class setPago
 */
public class setPago extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public setPago() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		PrintWriter out = response.getWriter();
		
		String idpersona = request.getParameter("idpersona");
		String montopago = request.getParameter("montopago");
		String idprestamo = request.getParameter("idprestamo");
		String estado = "1"; // request.getParameter("estado");

		out.println("<script>");
		out.println("alert('registro correcto'); window.parent.close();");
		out.println("</script>");

		conTarifa cp = new conTarifa();

		tarifa tarifa = new tarifa();
		proyecto prest = new proyecto();
		prest.setId(Integer.parseInt(idprestamo));

		String cup = "123456";

		tarifa.setCup(cup);

		tarifa.setEstado(Integer.parseInt(estado));
		tarifa.setMonto(Integer.parseInt(montopago));
		tarifa.setPrestamo(prest);

		try {
			cp.setPago(tarifa);
			response.sendRedirect("AdminPrestamos.jsp?idpersona=" + idpersona);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		out.close();

	}

}
